package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByMobile(String mobile) {
        //创建条件
        QueryWrapper<User> qw = new QueryWrapper<User>();
        qw.eq("mobile",mobile);
        //查询
        return userMapper.selectOne(qw);
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    //更新
    public void update(User user) {
        userMapper.updateById(user);
    }

    //根据id查询
    public User findById(Long id) {
        return userMapper.selectById(id);
    }
}
